  {  Petrova Tatjana
     2012 / 11 / 26
     This program  draws 100 figures.}
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;



type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

  Figure = class
    x, y : integer;
    procedure Draw; virtual; abstract;
  end;
  Square = class(Figure)
    a : integer;
    procedure Draw;  override;
  end;
  Circle = class(Figure)
    R,c : integer;
    constructor Create(newc : integer);
    procedure Draw ; override;
  end;
  FixedSquare = class(Square)
    constructor Create(newx, newy, newa : integer);

  end;
  RandomSquare = class(Square)
    constructor Create;

  end;


var
  Form1: TForm1;
  mas : array [0..99] of Figure;

implementation

{$R *.dfm}

constructor FixedSquare.Create(newx, newy, newa : integer);
begin
    x := newx;
    y := newy;
    a := newa;
end;
constructor Circle.Create (newc : integer);
begin
    x := random(Form1.Image1.Width);
    y := random(Form1.Image1.Height);
    R := 50;
    c:=  newc;
end;
constructor RandomSquare.Create;
begin
    x := random(Form1.Image1.Width);
    y := random(Form1.Image1.Height);
    a := 50;
end;
procedure Square.Draw;
begin
  Form1.Image1.Canvas.Rectangle(x, y, x+a, y+a);
end;

procedure Circle.Draw;
begin
  Form1.Image1.Canvas.Brush.Color:=c;
  Form1.Image1.Canvas.Ellipse(x, y, x+R, y+R);
  Form1.Image1.Canvas.Brush.Color:=clBlack;
end;


procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
 randomize;
  for i := 0 to 24 do
  begin
    mas[i]:=FixedSquare.Create(i*10, i*10, 20);
  end;
  for i := 24 to 49 do
  begin
    mas[i]:= RandomSquare.Create;
  end;
  for i := 49 to 99 do
  begin
    mas[i]:=Circle.Create(clRed);
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  for i := 0 to 24 do
  begin
    mas[i].Draw;
  end;
  for i := 25 to 49 do
  begin
    mas[i].Draw;
  end;
  for i := 50 to 99 do
  begin
    mas[i].Draw;
  end;
end;
end.






